import * as service from '../service'
import {Message} from 'element-ui'

var windowId
export const sendCmd = (type, control, row, callback=() => {}) => {
  let cmdMap = {
    'video-play': playVideo,
    'video-pause': pauseVideo,
    'video-stop': stopVideo,
    'video-replay': replayVideo,
    'video-silence': silenceVideo,
    'video-backward': backwardVideo,
    'video-forward': forwardVideo,
    'video-unslience': cancelSilenceVideo,
    'video-percent': changeVideoPercent,
    'audio-percent': changeAudioPercent,
    'video-getpercent': getVideoPercent,
    'audio-getpercent': getVideoAudioPercent,

    'image-open': openImage,
    'image-play': playImage,
    'image-pause': pauseImage,
    'image-first': firstImage,
    'image-last': lastImage,
    'image-previous': previousImage,
    'image-next': nextImage,

    'office-open': openOfficeFile,
    'office-play': playOfficeFile,
    'office-pause': pauseOfficeFile,
    'office-first': toFristOfficeFile,
    'office-previous': previousOffice,
    'office-next': nextOffice,
    'office-last': lastOffice,

    'application-open': openApplication,
    'application-refresh': refreshApplication,
    'application-close': closeApplication,

    'webApplication-open': openWebApplication,
    'webApplication-refresh': refreshWebApplication,
    'webApplication-next': nextWebApplication,
    'webApplication-prev': prevWebApplication,
    'webApplication-navigate': navigateWebApplication,


    'otherApplication-open': openOtherApplication,

    'captions-start': startCaptions,
    'captions-open': openCaptions,
    'captions-close': closeCaptions,

    'get-windowList': getWindowList,
    'close-window': closeWindow, // 关机
    'restart-window': restartWindow,
    'max-window': maxWindow,
    'min-window': minWindow,

    'get-extraWindow': getExtraWindowList,

    'window-open': openWindow, // 打开窗口
    'globalScene-open': openGlobalSceneWindow,
    'window-closeAll': closeAllWindow, // 关闭所有窗口
    'window-close': windowClose, // 关闭特定窗口
    'window-restoreSoftware': restoreSoftware,

    'move-multScreen': moveMultScreen,
    'resize-multScreen': resizeMultScreen,
    'open-multScreen': openMultScreen,

    'stream-open': openStream,
    'stream-play': playStream,
    'stream-pause': pauseStream,
    'stream-stop': stopStream,
    'stream-replay': replayStream,

    'show-save': saveShow,
    'show-play': playShow,
    'show-stop': stopShow,
    'show-next': nextShow,
    'show-prev': prevShow,

    'mouse-move': mouseMove,
    'mouse-leftSingle': mouseLeftSingle,
    'mouse-rightSingle': mouseRightSingle,
    'mouse-leftDouble': mouseLeftDouble,
    'mouse-rightDouble': mouseRightDouble,
    'mouse-leftDownWithMove': mouseLeftDownWithMove,
    'mouse-leftUp': mouseLeftUp,
    'scroll-down': scrollDown,
    'scroll-up': scrollUp,
    'mouse-moveLeft':  mouseMoveLeft,

    'keyboard-press': keyboard,

    'qrcode-enable':  enableQRcode,
    'qrcode-disable':  disableQRcode,

  }


  return cmdMap[`${type}-${control}`](row, callback)
}

function getExtraWindowList(row, callback=() => {}) {
  const cmd = JSON.stringify({"system":"control","cmd":"getAllDisplayList"})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}

function minWindow(row, callback=() => {}) {
  const cmd = JSON.stringify({"system":"control","cmd":"minWin"})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function maxWindow(row, callback=() => {}) {
  const cmd = JSON.stringify({"system":"control","cmd":"maxWin"})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function restartWindow(row, callback=() => {}) {
  const cmd = JSON.stringify({"system":"control","cmd":"restart"})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function closeWindow(row, callback=() => {}) {
  const cmd = JSON.stringify({"system":"control","cmd":"shutdown"})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function getWindowList(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"multScreen","cmd":"getAllWinParam"})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function setCaptionsConfig(row, callback=() => {}) {
  let obj = {
    "mode":"subtitles",
    "cmd":"setParagram",
    "name":row.name,
    "content":row.text,
    "scene":row.scene,
    "x":row.x,
    "y":row.y,
    "font":row.font,
    "size":row.size,
    "direction":row.direction,
    "color":row.color,
    "style":row.style,
    "width":row.width,
    "height":row.height,
    "alignment":row.alignment,
    "valignment":row.valignment,
    // "scroll":1,
    // "speed":100
  }
  const cmd = JSON.stringify(obj)
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function closeCaptions(row, callback=() => {}) {
  const cmd = JSON.stringify({"scene": row.scene,"mode":"subtitles","cmd":"close"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function openCaptions(row, callback=() => {}) {
  // 设置字幕属性
  setCaptionsConfig(row, () => {
    const cmd = JSON.stringify({"scene": row.scene,"mode":"subtitles","cmd":"open"})
    service.instructSend(cmd).then(() => {
      callback()
    }).catch(() => {
      // 错误处理
    })
  })
}
function startCaptions(row, callback=() => {}) {
  const cmd = JSON.stringify({"scene": row.scene,"mode":"subtitles","cmd":"setText","content": row.name})
  service.instructSend(cmd).then(() => {
    openCaptions(row, callback)
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function setScrollCaptions(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"subtitles","cmd":"setSroll","scene":row.scene,"scroll":1,"speed":100})
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function openOtherApplication(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"progress","value": row.percent * 10} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function navigateWebApplication(row, callback=() => {}) {
  if(!row.routerUrl) {
    Message.error('请输入指定网页')
    return
  }
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"web","content": row.routerUrl}  )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function getVideoAudioPercent(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"getVol"} )
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function getVideoPercent(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"getProgress"} )
  service.instructSend(cmd).then((res) => {
    callback(res.data)
  }).catch(() => {
    // 错误处理
  })
}
function changeAudioPercent(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"setVol","value": row.percent} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function changeVideoPercent(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"progress","value": row.percent * 10} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function nextWebApplication(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"web","cmd": 'next'} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function prevWebApplication(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"web","cmd": 'prev'} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function refreshWebApplication(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"web","cmd": 'refresh'} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function openWebApplication(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"web","content": row.content} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function closeApplication(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"extLink","cmd":"closeProcess","content": row.clean_process} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
// 没有看到refresh命令
// 改为关闭素材再切换素材
function refreshApplication(row, callback=() => {}) {
  closeApplication(row, () => {
    openWebApplication(row)
  });
}
function openApplication(row, callback=() => {}) {
// const test = "C:/Program Files (x86)/Tencent/WeChat/WeChat.exe"
  let cmd = JSON.stringify({"mode":"extLink","cmd":"openProcess","content": row.content});
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function nextOffice(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt","cmd":"next"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function lastOffice(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt","cmd":"last"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function previousOffice(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt","cmd":"prev"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
// 没看到ppt第一页和最后一页
function toFristOfficeFile(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt","cmd":"first"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function pauseOfficeFile(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt","cmd":"pause"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function playOfficeFile(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt", "cmd":"autostart", time: row.autoPlayImageNum})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function openOfficeFile(row, callback=() => {}) {
  let cmd = ''
  if(row.content.indexOf('ppt') !== -1) {
    cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt", "content": row.content})
  } else {
    cmd = JSON.stringify({"winId": row.windowId,"mode":"office", "content": row.content})
  }
  service.instructSend(cmd).then(() => {
    if(row.content.indenxOf('.ppt') !== -1) {
      const cmd = JSON.stringify({"winId": row.windowId,"mode":"ppt","cmd":"play"})
      service.instructSend(cmd).then(() => {
        callback()
      }).catch(() => {
        // 错误处理
      })
    }
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function nextImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture", "cmd":"next"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function previousImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture", "cmd":"prev"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function lastImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture", "cmd":"last"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function firstImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture", "cmd":"first"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function pauseImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture", "cmd":"autostop"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function playImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture","cmd":"autostart","time": row.autoTime})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function openImage(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"picture","content": row.content})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function playVideo(row, callback=() => {}) {
// ,"cmd":"play"
  const cmd = JSON.stringify({"winId": row.windowId, content: row.content,"mode":"movie","cmd":"play"})
  console.log('执行播放cmd ---', cmd)
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function pauseVideo(row, callback) {
  const cmd = JSON.stringify({"winId": row.windowId, "mode":"movie","cmd":"pause"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function stopVideo(row, callback) {
  const cmd = JSON.stringify({"winId": row.windowId, "mode":"movie","cmd":"stop"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function replayVideo(row, callback) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"replay"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function forwardVideo(row, callback) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"forward","value":10})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function backwardVideo(row, callback) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"backward","value":10})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function silenceVideo(row, callback) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"mute"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function cancelSilenceVideo(row ,callback) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"movie","cmd":"unmute"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function closeAllWindow(obj, callback) {
  const cmd = JSON.stringify({"mode":"multScreen","cmd":"closeAll"})
  if(Object.keys(obj).length === 0) {
    service.instructSend(cmd).then(() => {
      callback()
    }).catch(() => {
      // 错误处理
    })
  } else {
    console.log('obj ---', obj)
    service.instructSend(cmd, obj).then(() => {
      callback()
      console.log('执行回调')
    }).catch(() => {
      // 错误处理
    })
  }
}
function windowClose(windowId, callback) {
  const cmd = JSON.stringify({"mode":"multScreen","cmd":"close","id":windowId})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function restoreSoftware(){
  const cmd = JSON.stringify({"system":"control","cmd":"restoreSoftware"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function openWindow(obj, callback){
  const {row, content, subMode, i} = obj
  windowId = parseInt(i, 10) + 1
  console.log('row', obj)
  const clientDetail = JSON.parse(localStorage.getItem('clientDetail'))
  const rateX = Number(clientDetail.resolution_rate.split('*')[0])
  const rateY = Number(clientDetail.resolution_rate.split('*')[1])
  function extractNumber(str) {
    if(str.toString().indexOf('px') !== -1 || str.toString().indexOf('%') !== -1) {
      var matches = str.match(/(\d+)/);
      return matches ? Number(matches[0])  : null;
    }
  }
  if(row.coordinate != undefined && row.coordinate != null) {
    const coordinate = JSON.parse(row.coordinate)
    let cmdObj = {
      "mode":"multScreen",
      "cmd":"open",
      "id": windowId,
      // "name": row.media_name,
      "x": Math.floor(extractNumber(coordinate.left) / 100 * rateX),
      "y": Math.floor(extractNumber(coordinate.top) / 100 * rateY),
      "width": Math.floor(extractNumber(coordinate.width) / 100 * rateX),
      "height": Math.floor(extractNumber(coordinate.height) / 100 * rateY),
      // "content" : content,
      "content": content.media_name,
      "subMode":subMode,
    }

    // 网页内容打开链接
    if(content.media_type == 5) {
      console.log('contet ----', content)
      cmdObj.content = content.location
    }
    const cmd = JSON.stringify(cmdObj)
    // const cmd = row.map(item => {
    //   const coordinate = JSON.parse(item.coordinate)
    //   const top = extractNumber(coordinate.top) / 100 * rateX + 'px'
    //   const left = extractNumber(coordinate.left) / 100 * rateY + 'px'
    //   const width =  extractNumber(coordinate.width) / 100 * rateX + 'px'
    //   const height =  extractNumber(coordinate.height) / 100 * rateY + 'px'
    //   return JSON.stringify({
    //     "mode":"multScreen","cmd":"open",
    //     "id":item.id,
    //     "x": top ,
    //     "y": left ,
    //     "width": width ,
    //     "height": height,
    //     "content" : content,
    //     "subMode":subMode,
    //   })
    // })
    console.log('cmd', cmd)
    service.instructSend(cmd).then(() => {
      callback()
    }).catch(() => {
      // 错误处理
    })
  }
}
function openGlobalSceneWindow(obj, callback) {
  const {row, content, subMode, i, client} = obj
  windowId = parseInt(i, 10) + 1
  const clientDetail = {...client}
  const rateX = Number(clientDetail.resolution_rate.split('*')[0])
  const rateY = Number(clientDetail.resolution_rate.split('*')[1])
  function extractNumber(str) {
    if(str.toString().indexOf('px') !== -1 || str.toString().indexOf('%') !== -1) {
      var matches = str.match(/(\d+)/);
      return matches ? Number(matches[0])  : null;
    }
  }
  if(row.coordinate != undefined && row.coordinate != null) {
    const coordinate = JSON.parse(row.coordinate)
    let cmdObj = {
      "mode":"multScreen",
      "cmd":"open",
      "id": windowId,
      "name": row.media_name,
      "x": Math.floor(extractNumber(coordinate.left) / 100 * rateX),
      "y": Math.floor(extractNumber(coordinate.top) / 100 * rateY),
      "width": Math.floor(extractNumber(coordinate.width) / 100 * rateX),
      "height": Math.floor(extractNumber(coordinate.height) / 100 * rateY),
      // "content" : content,
      "content": content.media_name,
      "subMode":subMode,
    }
    // 网页内容打开链接
    if(content.media_type == 5) {
      console.log('contet ----', content)
      cmdObj.content = content.location
    }
    const cmd = JSON.stringify(cmdObj)

    service.instructSend(cmd, client).then((result) => {
      callback(result)
    }).catch(() => {
      // 错误处理
    })
  }
}
function moveMultScreen(obj, callback){
  const cmd = JSON.stringify({"mode":"multScreen","cmd":"move", "id": obj.id, 'x':obj.x, 'y':obj.y})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function resizeMultScreen(obj, callback){
  const cmd = JSON.stringify({"mode":"multScreen","cmd":"resize", "id": obj.id, 'width':obj.width, 'height':obj.height})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
function openMultScreen(obj, callback){
  const cmdObj = {
    "mode":"multScreen",
    "cmd":"open",
    "id":obj.id,
    "name":obj.name,
    "x":obj.x,
    "y":obj.y,
    "width":obj.width,
    "height":obj.height,
    "content":obj.content,
    "subMode":obj.subMode,
  }
  const cmd = JSON.stringify(cmdObj)
  service.instructSend(cmd).then((result) => {
    if(obj.subMode == 'show'){
      saveShow(obj);
    }
    callback(result)
  }).catch(() => {
    // 错误处理
  })
}

function openStream(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"stream","content": row.content} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function playStream(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"stream","cmd": "play"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function pauseStream(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"stream","cmd": "pause"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function stopStream(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"stream","cmd": "stop"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function replayStream(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"stream","cmd": "replay"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function saveShow(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"pc_control","cmd":"updateShowList","content": row.content} )
  service.instructSend(cmd).then(() => {
    openShow(row);
    // playShow(row);
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function openShow(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"show","content":row.content.showList[0].name} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function playShow(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"show","cmd":"play"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function stopShow(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"show","cmd":"stop"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function prevShow(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"show","cmd":"prev"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function nextShow(row, callback=() => {}) {
  const cmd = JSON.stringify({"winId": row.windowId,"mode":"show","cmd":"next"} )
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}


function mouseMoveLeft(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"moveLeft","speed":10})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseMove(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"move","x":row.x,"y":row.y})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseLeftSingle(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"leftSingle"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseLeftDouble(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"leftDouble"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseRightSingle(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"rightSingle"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseRightDouble(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"rightDouble"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseLeftDownWithMove(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"leftDownWithMove","x":row.x,"y":row.y})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function mouseLeftUp(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"leftUp"})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function keyboard(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"keyboard","cmd": row})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function scrollDown(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"scrollDown", "speed":row})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function scrollUp(row, callback=() => {}) {
  const cmd = JSON.stringify({"mode":"mouse","cmd":"scrollUp", "speed":row})
  service.instructSend(cmd).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}

function enableQRcode(url, clientDetial, callback=() => {}) {
  const cmd = JSON.stringify({"system":"qrcode","cmd":"setQRCodeLink","content":url})
  service.instructSend(cmd, clientDetial).then(() => {
    callback();
  }).catch(() => {
    // 错误处理
  })
}

function disableQRcode(clientDetial, callback=() => {}) {
  const cmd = JSON.stringify({"system":"qrcode","cmd":"disableQRCode"})
  service.instructSend(cmd, clientDetial).then(() => {
    callback()
  }).catch(() => {
    // 错误处理
  })
}
